# 导包
import unittest
from api.goods import GoodsAPI


# 创建测试类
class TestGoodsAPI(unittest.TestCase):

    # 初始化
    list_id = None
    goods_id = None

    # 前置处理
    def setUp(self) -> None:
        self.goods_api = GoodsAPI()

    # 后置处理
    def tearDown(self) -> None:
        pass

    # 测试获取商品分类
    def test01_get_goods_list(self):
        response = self.goods_api.get_goods_list()
        print(response.json())
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertIn("description", response.text)
        # 提取返回的数据
        TestGoodsAPI.list_id = response.json()[0].get("id")
        print(TestGoodsAPI.list_id)

    # 测试商品分类下的商品信息
    def test02_get_goods_list_info(self):
        response = self.goods_api.get_goods_list_info(TestGoodsAPI.list_id)
        print(response.json())
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertIn("name", response.text)
        # 提取返回数据
        TestGoodsAPI.goods_id = response.json()[2].get("id")
        print(TestGoodsAPI.goods_id)

    # 测试商品详情信息
    def test03_get_goods_info(self):
        response = self.goods_api.get_goods_info(TestGoodsAPI.goods_id)
        print(response.json())
        # 断言
        self.assertEqual(200, response.status_code)
        self.assertIn("price", response.text)







































































